package jnote;

import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.io.IOException;
import javax.swing.JTextArea;

public class Paste {
    public void paste(Clipboard clip, JTextArea tx) {
        /*
         * Get the content of the system clipboard
         */
        Transferable content = clip.getContents(this);
        
        if(content != null) {
            try {
                /*
                 * If the content of the clipboard its not null
                 * paste into the text area, only if the content is a String,
                 * and paste it in the place specified by the caret
                 */
                String dstData = (String)content.getTransferData(DataFlavor.stringFlavor);
                tx.insert(dstData, tx.getCaretPosition());
            } catch(UnsupportedFlavorException | IOException e) {
            }
        }
    }
}
